<template>
	<view class="order-list">
		<!-- 顶部导航 -->
		<view class="nav-bar">
			<view v-for="(item, index) in navItems" :key="index" :class="['nav-item', { active: currentTab === index }]"
				@tap="changeTab(index)">
				{{ item }}
			</view>
		</view>

		<!-- 订单列表 -->
		<scroll-view scroll-y class="order-scroll">
			<view v-if="orderList.length === 0" class="empty-list">
				<image src="/static/empty-box.png" mode="aspectFit" class="empty-icon"></image>
				<text>暂无订单</text>
			</view>
			<view v-else class="order-item" v-for="(order, index) in orderList" :key="index">
				<view class="order-header">
					<text class="order-number">订单号: {{ order.orderNumber }}</text>
					<text :class="['order-status', order.statusClass]">{{ order.status }}</text>
				</view>
				<view class="order-content">
					<image :src="order.productImage" mode="aspectFill" class="product-image"></image>
					<view class="order-details">
						<text class="product-name">{{ order.productName }}</text>
						<text class="order-date">下单时间: {{ order.orderDate }}</text>
					</view>
				</view>
				<view class="order-footer">
					<text class="order-amount">总价: ¥{{ order.amount.toFixed(2) }}</text>
					<button class="action-button" :class="order.actionClass">{{ order.actionText }}</button>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navItems: ['全部', '待支付', '待发货', '已完成'],
				currentTab: 0,
				orderList: []
			}
		},
		methods: {
			changeTab(index) {
				this.currentTab = index;
				this.getOrderList();
			},
			getOrderList() {
				// 模拟数据，实际应用中需要替换为真实的 API 调用
				const mockData = [{
						orderNumber: 'OR001',
						status: '待支付',
						statusClass: 'status-pending',
						amount: 99.99,
						productName: '时尚休闲鞋',
						productImage: '/static/goods/2.webp',
						orderDate: '2023-04-15 14:30',
						actionText: '立即支付',
						actionClass: 'pay-button'
					},
					{
						orderNumber: 'OR002',
						status: '待发货',
						statusClass: 'status-processing',
						amount: 199.99,
						productName: '智能手表',
						productImage: '/static/goods/3.webp',
						orderDate: '2023-04-14 09:15',
						actionText: '催促发货',
						actionClass: 'urge-button'
					},
					{
						orderNumber: 'OR003',
						status: '已完成',
						statusClass: 'status-completed',
						amount: 299.99,
						productName: '无线耳机',
						productImage: '/static/goods/4.webp',
						orderDate: '2023-04-10 18:45',
						actionText: '评价',
						actionClass: 'review-button'
					},
				];

				this.orderList = mockData.filter(order => {
					if (this.currentTab === 0) return true;
					return order.status === this.navItems[this.currentTab];
				});
			}
		},
		mounted() {
			this.getOrderList();
		}
	}
</script>

<style lang="scss" scoped>
	.order-list {
		display: flex;
		flex-direction: column;
		height: 100vh;
		background-color: #f5f5f5;
	}

	.nav-bar {
		display: flex;
		justify-content: space-around;
		padding: 20rpx 0;
		background-color: #ffffff;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	}

	.nav-item {
		font-size: 28rpx;
		color: #666;
		padding: 10rpx 20rpx;
		border-radius: 30rpx;
		transition: all 0.3s ease;

		&.active {
			color: #ffffff;
			background-color: #007aff;
			font-weight: bold;
		}
	}

	.order-scroll {
		width: 95%;
		padding: 20rpx;
	}

	.order-item {
		background-color: #fff;
		border-radius: 20rpx;
		padding: 30rpx;
		margin-bottom: 30rpx;
		box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
	}

	.order-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.order-number {
		font-size: 26rpx;
		color: #666;
	}

	.order-status {
		font-size: 24rpx;
		padding: 6rpx 16rpx;
		border-radius: 20rpx;

		&.status-pending {
			background-color: #ffefd5;
			color: #ffa500;
		}

		&.status-processing {
			background-color: #e6f7ff;
			color: #1890ff;
		}

		&.status-completed {
			background-color: #f6ffed;
			color: #52c41a;
		}
	}

	.order-content {
		display: flex;
		margin-bottom: 20rpx;
	}

	.product-image {
		width: 160rpx;
		height: 160rpx;
		border-radius: 10rpx;
		margin-right: 20rpx;
	}

	.order-details {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.product-name {
		font-size: 28rpx;
		font-weight: bold;
		color: #333;
	}

	.order-date {
		font-size: 24rpx;
		color: #999;
	}

	.order-footer {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.order-amount {
		font-size: 32rpx;
		font-weight: bold;
		color: #ff6b6b;
	}

	.action-button {
		font-size: 24rpx;
		padding: 10rpx 30rpx;
		border-radius: 30rpx;
		border: none;

		&.pay-button {
			background-color: #ff6b6b;
			color: #ffffff;
		}

		&.urge-button {
			background-color: #ffd166;
			color: #ffffff;
		}

		&.review-button {
			background-color: #4ecdc4;
			color: #ffffff;
		}
	}

	.empty-list {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		height: 100%;
		color: #999;

		.empty-icon {
			width: 200rpx;
			height: 200rpx;
			margin-bottom: 20rpx;
		}
	}
</style>